﻿Public Class Frm_Recherche
    Public countA As Integer = 0
    Public countC As Integer = 0
    Public focs As String = ""
    Private Sub Frm_Recherche_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Partager.frmafect.Enabled = True
        Partager.ar = False
        Partager.typee = ""
    End Sub

    Private Sub Frm_Recherche_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Partager.remplirClient(Comb_nom)
        Partager.remplirEnemie(Comb_adv)
        '-------------------------------
        Comb_nom.SelectedIndex = -1
        Partager.deClt.Key = -1
        Comb_adv.SelectedIndex = -1

        focs = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Enabled = False
        Partager.frmMoule = New Form
        Partager.frmMoule = Me
        Partager.type_rech_mowakil = "Frm_Ref"
        Frm_Rech_Clients.Show()
    End Sub

    Private Sub Comb_nom_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_nom.SelectedIndexChanged

        If focs = "" Then
            focs = "client"
        End If
        If Comb_nom.Text <> "" And focs = "client" Then
            Comb_marji3ona.Items.Clear()
            Comb_marji3ona.Text = ""

            Partager.deClt = DirectCast(Comb_nom.SelectedItem, DictionaryEntry)
            Partager.remplir_CombAdvr(CInt(Partager.deClt.Key), Comb_adv)

        ElseIf Comb_adv.Text <> "" And Comb_nom.Text <> "" And focs = "adver" Then

            Partager.deAdv = DirectCast(Comb_adv.SelectedItem, DictionaryEntry)
            Partager.deClt = DirectCast(Comb_nom.SelectedItem, DictionaryEntry)
            If Partager.ar Then
                Partager.remplir_dossier(CInt(Partager.deClt.Key), CInt(Partager.deAdv.Key), Comb_marji3ona, True)
            Else
                Partager.remplir_dossier(CInt(Partager.deClt.Key), CInt(Partager.deAdv.Key), Comb_marji3ona)
            End If
        ElseIf focs = "dossier" Then
            focs = ""
            Exit Sub
        Else
            Comb_marji3ona.Items.Clear()
            Comb_marji3ona.Text = ""
        End If
    End Sub

 

    Private Sub Comb_adv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_adv.SelectedIndexChanged
        If focs = "" Then
            focs = "adver"
        End If
        If Comb_adv.Text <> "" And focs = "adver" Then
            Comb_marji3ona.Items.Clear()
            Comb_marji3ona.Text = ""

            Partager.deClt = DirectCast(Comb_adv.SelectedItem, DictionaryEntry)
            Partager.remplir_CombClient(CInt(Partager.deClt.Key), Comb_nom)

        ElseIf Comb_adv.Text <> "" And Comb_nom.Text <> "" And focs = "client" Then

            Partager.deAdv = DirectCast(Comb_adv.SelectedItem, DictionaryEntry)
            Partager.deClt = DirectCast(Comb_nom.SelectedItem, DictionaryEntry)
            If Partager.ar Then
                Partager.remplir_dossier(CInt(Partager.deClt.Key), CInt(Partager.deAdv.Key), Comb_marji3ona, True)
            Else
                Partager.remplir_dossier(CInt(Partager.deClt.Key), CInt(Partager.deAdv.Key), Comb_marji3ona)
            End If
        ElseIf focs = "dossier" Then
            focs = ""
            Exit Sub
        Else
            Comb_marji3ona.Items.Clear()
            Comb_marji3ona.Text = ""
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        If Comb_marji3ona.Text <> "" Then

            Partager.deClt = DirectCast(Comb_marji3ona.SelectedItem, DictionaryEntry)
            Dim avo As Dossier
            Dim str As String = "Comb_marji3ona"
            If Partager.typee = "Frm_Dossier" Then
                Partager.typee = ""
                Dim j As Integer = -1
                Try
                    'For Each khib As Dossier In Partager.moi.List_info_fichier
                    '    If khib.Archive = False Then
                    '        j += 1
                    '    End If
                    '    If CInt(Partager.deClt.Key) = khib.id Then
                    '        Frm_Dossier.List_tous.Items(j).Focused = True
                    '        Frm_Dossier.List_tous.Items(j).Selected = True
                    '        Partager.type = ""
                    '    End If
                    'Next
                    '------------------------------------------------------------
                    For i As Integer = 0 To Frm_Dossier.List_tous.Items.Count - 1
                        If CInt(Partager.deClt.Key) = CInt(Frm_Dossier.List_tous.Items(i).SubItems(0).Text) Then
                            Frm_Dossier.List_tous.Items(i).Focused = True
                            Frm_Dossier.List_tous.Items(i).Selected = True
                            Partager.typee = "true"
                            Exit For
                        End If
                    Next
                    If Partager.typee = "" Then
                        MsgBox("هذا الملف غير موجود في " & Frm_Dossier.Comb_selection.Text)
                        Partager.nonInitial = New ArrayList
                        Partager.nonInitial.Add("Comb_selection")
                        Partager.vider(Frm_Dossier, Partager.nonInitial)
                        Frm_Dossier.selectYear()
                    End If
                    Partager.typee = ""
                    Me.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                Try
                    For Each khib As Dossier In Partager.moi.List_info_fichier
                        If CInt(Partager.deClt.Key) = khib.id Then
                            avo = khib
                        End If
                    Next
                    For Each cmb As Control In Partager.frmafect.Controls
                        If TypeOf cmb Is ComboBox Then
                            If Partager.type = "combo2" Then
                                str = "cmbOrigin"
                                Partager.type = ""
                            End If
                            If cmb.Name = str Then
                                cmb.Text = avo.Num & "  |  " & avo.Type_appel & "  |  " & avo.Tribunal
                                Exit For
                            End If
                        End If
                    Next
                    Me.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If


        End If
    End Sub

    Private Sub Btn_Rech_Doss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Rech_Doss.Click
        Me.Enabled = False
        Partager.type = Me.Name
        Frm_Rech_Dossier.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Enabled = False
        Partager.frmMoule = New Form
        Partager.frmMoule = Me
        Partager.type_rech_adver = "Frm_Idafa_khossoum"
        Frm_Rech_Adver.Show()
    End Sub
End Class